#include "talisman.h"
#include "qmessagebox.h"
#include "AdventureCardArea.h"
#include "Character\Character.h"
#include "Character\PlayerCharacter.h"
#include "PlayerArea.h"
#include "Map\PositionKeeper.h"
#include "Map\Map.h"
#include "FightScreen.h"

void Talisman::becomeToad(void)
{
	mPlayer->setToad(true);
	map->updateContents();
	map->update();
	mArea->update();
}

void Talisman::drawOneAdventureCard(void) 
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("Now, one adventure card will be drawn for you!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();
	mAdventureCardArea->nextCard();
}

Outcome::Outcome Talisman::fightTiger(void) 
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("Now, you'll have to fight a tiger!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();

	NonPlayerCharacter tiger("Tiger", "Tiger is a wild animal that attacks without provocation!", 8, 1);
	tiger.setPicture("Images\\tiger_large.gif");

	FightScreen fs(*mPlayer, tiger, this);
	fs.exec();

	Outcome::Outcome wFightOutcome  = fs.getFightOutcome();

	if( Outcome::eWinFight == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You won! The winner of this fight gets 3 strength counters and 2 gold coins. Congratulations!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
		int wOldStrength = mPlayer->getStrengthCounter();
		int wOldGold = mPlayer->getGoldenCoinNumberInPossession();
		mPlayer->setStrengthCounter(wOldStrength + 3);
		mPlayer->setGoldenCoinNumberInPossession(wOldGold + 2);

		// Remove the killed enemy from the map space
		mPositionKeeper->getCharacterLocation(mPlayer)->setInstruction(0);
	}
	else if( Outcome::eLoseFight == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You've lost the fight, so you lose 1 life counter!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
		int wOldLife = mPlayer->getLifeCounter();
		if (wOldLife > 0)
			mPlayer->setLifeCounter(wOldLife - 1);
	}
	else if( Outcome::eEvaded == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You have evaded the fight; nobody got hurt!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
	}
	else if( Outcome::eStandoff == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("Standoff! Nobody got hurt."));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
	}

	return wFightOutcome;
}

Outcome::Outcome Talisman::fightBear(void)
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("Now, you'll have to fight a bear!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();

	NonPlayerCharacter bear("Bear", "Bear is HUGE wild animal", 4, 2);
	bear.setPicture("Images\\bear_large.gif");

	FightScreen fs(*mPlayer, bear, this);
	fs.exec();

	Outcome::Outcome wFightOutcome  = fs.getFightOutcome();

	if( Outcome::eWinFight == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You won! The winner of this fight gets 1 strength counters and 1 gold coins. Congratulations!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
		int wOldStrength = mPlayer->getStrengthCounter();
		int wOldGold = mPlayer->getGoldenCoinNumberInPossession();
		mPlayer->setStrengthCounter(wOldStrength + 1);
		mPlayer->setGoldenCoinNumberInPossession(wOldGold + 1);
		
		// Remove the killed enemy from the map space
		mPositionKeeper->getCharacterLocation(mPlayer)->setInstruction(0);
	}
	else if( Outcome::eLoseFight == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You've lost the fight, so you lose 1 life counter!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
		int wOldLife = mPlayer->getLifeCounter();
		if (wOldLife > 0)
			mPlayer->setLifeCounter(wOldLife - 1);
	}
	else if( Outcome::eEvaded == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("You have evaded the fight; nobody got hurt!"));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
	}
	else if( Outcome::eStandoff == wFightOutcome)
	{
		QMessageBox msgBox;
		QString msg = "";
		msg.append(QString("Standoff! Nobody got hurt."));
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
	}

	return wFightOutcome;
}

void Talisman::restartGame(void)
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("Woops! Looks like you'll have to start all over!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();
	mPositionKeeper->placeCharacter(mPlayer, map->getOuterRegionStartSpace());
	map->updateContents();
}

void Talisman::loseOneLife(void)
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("Woops! You've lose a life!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();
	int wPlayerLifeCounter = mPlayer->getLifeCounter();
	if (wPlayerLifeCounter > 0)
		mPlayer->setLifeCounter(wPlayerLifeCounter - 1);
}

void Talisman::winTheGame(void)
{
	QMessageBox msgBox;
	QString msg = "";
	msg.append(QString("CONGRATULATION!\n\nYOU HAVE REACHED THE CROWN OF COMMAND!\n\nYOU ARE THE WINNER!"));
	msgBox.setText(msg);
	msgBox.setIcon(QMessageBox::Information);
	msgBox.exec();
}